package com.ny.config;

import com.ny.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Resource
    private LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册拦截器并设置拦截路径
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**")  // 拦截所有请求
                .excludePathPatterns("/login", "/register")  // 排除登录和注册接口
                .excludePathPatterns("/sendEmailCode", "/updatePasswordByEmail", "/findUserByEmail")  // 排除验证码相关接口
                .excludePathPatterns("/error");  // 排除错误页面

    }
}